package team.seekers.hula.question.answer.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.common.entity.VisibilityUpdateDTO;
import team.seekers.hula.question.answer.entity.vo.AnswerListVO;
import team.seekers.hula.question.answer.service.AnswerService;
import team.seekers.hula.auth.service.MindUtils;
import team.seekers.hula.question.answer.service.AnswerGoodService;
import team.seekers.hula.question.answer.entity.dto.AnswerAddDTO;
import team.seekers.hula.question.answer.entity.dto.AnswerQueryDTO;
import team.seekers.hula.question.answer.entity.vo.AnswerInfoVO;
import team.seekers.hula.question.answer.entity.dto.AnswerUpdateDTO;

/**
 * <p>
 * 一个回答 前端控制器
 * </p>
 *
 * @author hbc
 * @since 2021-02-15
 */
@Controller
@ApiResponseBody
@RequestMapping("/answer")
public class AnswerController {

    @Autowired
    private AnswerService answerService;

    @Autowired
    private AnswerGoodService answerGoodService;

    @PostMapping("/add")
    public void add(@RequestBody AnswerAddDTO addVO){
        answerService.add(addVO);
    }

    @DeleteMapping("/delete")
    public void delete(@RequestParam("answerId") String id){
        answerService.delete(id);
    }

    @PostMapping("/update/info")
    public void update(@RequestBody AnswerUpdateDTO updateVO){
        answerService.updateInfo(updateVO);
    }

    @PostMapping("/update/visibility")
    public void updateVisibility(@RequestBody VisibilityUpdateDTO updateDTO){
        answerService.updateVisibility(updateDTO);
    }

    @GetMapping("/info")
    public AnswerInfoVO get(@RequestParam String id){
        return answerService.get(id, MindUtils.getUserId());
    }

    //分类型分页查询按照热度排序（热榜）
    @GetMapping("/page")
    public PageResult<AnswerListVO> pageOrderByHeat(AnswerQueryDTO answerQuery){
        return answerService.page(answerQuery);
    }

    // 如果没点赞则点赞，如果点了则取消赞
    @GetMapping("/like/change")
    public void changeGood(@RequestParam String id){
        answerGoodService.changeGood(id,MindUtils.getUserId());
    }

}

